package com.huaxin.hxmoduleworkorder.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.huaxin.hxmoduleworkorder.common.enums.MaintenanceOrderOperation;
import com.huaxin.hxmoduleworkorder.common.enums.MaintenanceOrderOperatorRole;
import com.huaxin.hxmoduleworkorder.dto.ResponseResult;
import com.huaxin.hxmoduleworkorder.dto.request.*;
import com.huaxin.hxmoduleworkorder.dto.response.MaintenanceOrderDetailRespDto;
import com.huaxin.hxmoduleworkorder.models.MaintenanceOrder;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public interface MaintenanceOrderService extends IService<MaintenanceOrder> {
    /* *********************************************************************
     * 工单基础 CRUD 操作
     ********************************************************************* */
    ResponseResult<MaintenanceOrder> create(MaintenanceOrderCreateReqDTO in);

    MaintenanceOrder getOrderById(String id);

    ResponseResult<String> update(MaintenanceOrderUpdateReqDTO in);

    ResponseResult<String> delete(MaintenanceOrderDeleteReqDto in);

    /* *********************************************************************
     * 工单流程与状态管理
     ********************************************************************* */

    ResponseResult<String> getOrderStatus(String id);

    List<MaintenanceOrderOperation> getAvailableOperations(String orderId, MaintenanceOrderOperatorRole operatorRole);

    Boolean canOperate(String id, MaintenanceOrderOperation operation, MaintenanceOrderOperatorRole operatorRole);

    void updateStatus(MaintenanceOrderUpdateStatusReqDTO in, Consumer<MaintenanceOrder> additionalUpdater);

    ResponseResult<String> submit(MaintenanceOrderSubmitReqDto in);

    ResponseResult<String> review(MaintenanceOrderReviewReqDto in);

    ResponseResult<String> reject(MaintenanceOrderRejectReqDto in);

    ResponseResult<String> rollback(MaintenanceOrderRollbackReqDto in);

    ResponseResult<String> reassign(MaintenanceOrderAssignReqDto in);

    ResponseResult<String> complete(MaintenanceOrderCompleteReqDto in);

    ResponseResult<String> cancel(MaintenanceOrderCancelReqDto in);

    void syncOrderStatus(String orderId);

    /* *********************************************************************
     * 分页与条件查询
     ********************************************************************* */

    ResponseResult<Page<MaintenanceOrder>> pageQuery(MaintenanceOrderPageListReqDTO in);

    MaintenanceOrderDetailRespDto detail(String id);

    /* *********************************************************************
     * 统计与报表
     ********************************************************************* */

    ResponseResult<Map<String, Long>> countByStatus();

    ResponseResult<Long> countInRange(LocalDateTime startTime, LocalDateTime endTime);

    ResponseResult<List<MaintenanceOrder>> listOverdueOrders(long thresholdHours);
}